package edu.ccut.saturn.workflow.activity.execute;

import java.util.HashMap;
import java.util.List;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.workflow.model.ActivityInfo;
import edu.ccut.saturn.workflow.model.DataInfo;
import edu.ccut.saturn.workflow.model.WorkFlowInfo;

public class SetFormDataValue extends DefaultComponent {
	@SuppressWarnings("unchecked")
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		WorkFlowInfo workflowInfo= (WorkFlowInfo)parameterContext.getParameterValue(0);
		HashMap<String ,String> formdataValue = (HashMap<String,String>)parameterContext.getParameterValue(1);
		String activity_define_id = (String)parameterContext.getParameterValue(2);
		List<ActivityInfo> actlist = workflowInfo.getActivities();
		for(ActivityInfo acitvity : actlist){
			if(activity_define_id.equals(acitvity.getId())){
				List<DataInfo> formdata = acitvity.getFormData();//得到活动中定义的表单数据
				for(DataInfo data  : formdata){
					if(formdataValue.containsKey(data.getKey())){
						//将值放到DataInfo中   注* DataInfo中Value属性在解析工作流定义时是无值的
						//设立此属性是为了封装好带值对象传递给表现层，用来显示自动表单
						data.setValue(formdataValue.get(data.getKey()));
					}
				}
				parameterContext.setParameter(3, formdata);
				break;
			}
		}
	}
}